package logic

import (
	"common/model"
	"context"
	"errors"
	"github.com/jjl309/oneGroup"
	user "user_srv/proto"
)

func (u *UserServer) UserLogin(ctx context.Context, req *user.UserLoginRequest) (*user.UserLoginResponse, error) {
	key := "code:" + req.Tel + ":"
	res := oneGroup.Rdb.Get(context.Background(), key).Val()
	if res != req.Code {
		return nil, errors.New("验证码错误")
	}
	var users model.User
	err := users.GetUserInfoByTel(req.Tel)
	if err != nil {
		return nil, err
	}
	if users.Id == 0 {
		return nil, errors.New("请前往注册")
	}
	return &user.UserLoginResponse{Userid: users.Id}, nil
}
